package info.rflow.actions;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;


/**
 * Opens a given file in the systems default editor
 *
 * @author Holger Brandl
 */
public class OpenFileAction extends AbstractAction {


    private File file;


    public OpenFileAction(File file) {
        this.file = file;

        putValue(NAME, "Open '" + file.getName() + "'");
        //        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.ALT_MASK));
    }


    public void actionPerformed(ActionEvent e) {
        try {

            if (file.isFile()) {
                Desktop.getDesktop().open(file);
            }

        } catch (IOException e1) {
            e1.printStackTrace();
        }

    }
}
